const app     = getApp(),
      api     = require("../../utils/api.js"),
      request = require("../../service/request.js");
var   page = 0,
      page1 = 1;

Page( {  
  data: {  
    /*页面配置 */  
    winWidth: 0,  
    winHeight: 0,  
    currentTab: 0,// tab切换 
    //面经数据
    MJList:{},
    //公司印象数据
    companyName:"百度",
    impIcon:['环境氛围好', '发展前景好', '工作压力大', '单休','考核制度严'],
    profess:"JAVA研发工程师",
    salary:"14k*14.6",
    pageView:60,
    reliability:10,
    // 自定义自己喜欢的颜色
    colorArr: ["#EE2C2C", "#ff7070", "#EEC900", "#4876FF", "#ff6100",
      "#7DC67D", "#E17572", "#7898AA", "#C35CFF", "#33BCBA", "#C28F5C",
      "#FF8533", "#6E6E6E", "#428BCA", "#5cb85c", "#FF674F", "#E9967A",
      "#66CDAA", "#00CED1", "#9F79EE", "#CD3333", "#FFC125", "#32CD32",
      "#00BFFF", "#68A2D5", "#FF69B4", "#DB7093", "#CD3278", "#607B8B"],
    // 存储随机颜色
    randomColorArr: []
  },  
  onLoad: function(options) {  
    var that = this;  
    var API_GSYX = api.getCompanyImp + "?page=" + page1;  //公司印象API
    request.get(`${api.getInterviewExp}?page=${page}`, {}, app.globalData.sessionid).then(res => {
      console.log(res.data);
      that.setData({
        MJList:res.data
      })
    })

    //获取系统信息
    wx.getSystemInfo({
      success: function (res) {
        var clientHeight = res.windowHeight-120,
        clientWidth = res.windowWidth,
        rpxR = 750 / clientWidth;
        var calc = clientHeight * rpxR;
        //console.log(calc)
        that.setData({
          winHeight: calc
        });
      }
    });

    let labLen = that.data.impIcon.length,
        colorArr = that.data.colorArr,
        colorLen = colorArr.length,
        randomColorArr = [];
      //判断执行
    do{
      let random = colorArr[Math.floor(Math.random() * colorLen)];
      randomColorArr.push(random);
      labLen--;
    } while (labLen > 0)

    that.setData({ 
      randomColorArr: randomColorArr
    });
    console.log(that.data.randomColorArr);
  },  
  /** 
     * 滑动切换tab 
     */  
  bindChange: function( e ) {  
  
    var that = this;  
    that.setData( { currentTab: e.detail.current });  
  
  },  
  /** 
   * 点击tab切换 
   */  
  swichNav: function( e ) {  
  
    var that = this;  
  
    if( this.data.currentTab === e.target.dataset.current ) {  
      return false;  
    } else {  
      that.setData( {  
        currentTab: e.target.dataset.current  
      })  
    }  
  },
  write:function(){
    var that = this; 
    if( this.data.currentTab === 0){
      wx.navigateTo({
        url: './issueMj/issueMj'
      })
    } else {
      wx.navigateTo({
        url: './issueImp/issueImp'
      })
    }
  },


  //触底加载更多
  pullUpLoad: function() {
    var that = this; 
    
    if (that.data.currentTab===0) {
      page++;
      request.get(`${api.getInterviewExp}?page=${page}`, {}, app.globalData.sessionid).then(res => {
        var isBottom = (!res.data.length==0)?true:false;

          if(isBottom){
            wx.showLoading({
              title: '加载更多数据',
              icon: 'loading',
              duration:2000
            })
            var moment_list = that.data.MJList;
            for (var i = 0; i < res.data.length; i++) {
              moment_list.push(res.data[i]);
            }

            that.setData({
              MJList:moment_list
            })
            wx.hideLoading();
            console.log("面经加载page="+page);
            console.log(res.data);
          } else {
            wx.showLoading({
              title: '亲，到底啦！',
              icon: 'loading',
              duration:700
            })
            page--;
            console.log("面经加载page="+page);
          }
      })
     
    } else if(that.data.currentTab===1) {
        // page1++;
        // var API_JYXX = API_URL1 + "&page=" + page1;
        // wx.request({
        //   url:API_JYXX,
        //   data:{},
        //   header:{
        //     "sessionid": app.globalData.sessionid,
        //     'Content-Type': 'application/json'
        //   },
        //   success:function (res){

        //     var isBottom = res.data?true:false;

        //     if(isBottom){
        //       wx.showLoading({
        //         title: '加载更多数据',
        //         icon: 'loading',
        //         duration:2000
        //       })
        //       var moment_list = that.data.list1;
       
        //       for (var i = 0; i < res.data.length; i++) {
        //         moment_list.push(res.data[i]);
        //       }

        //       that.setData({
        //         list1:moment_list
        //       })
        //       that.randomColor1();
        //       wx.hideLoading();
        //       console.log("就业信息网加载page="+page1);
        //       console.log(res.data);
        //     } else {
        //       wx.showLoading({
        //         title: '亲，到底啦！',
        //         icon: 'loading',
        //         duration:700
        //       })
        //       page1--;
        //       console.log("就业信息网加载page="+page1);
        //     }
        //   }
        // })
        console.log(2);
      }
    
    
  },

  //分享
  onReady: function (e) { 
    wx.showShareMenu({ 
      withShareTicket:true 
    }); 
  },
  onShareAppMessage: function () {
    let that = this;
    return {
      title: '校招SSP', // 转发后 所显示的title
      path: '/pages/find/find', // 相对的路径
      success: (res)=>{    // 成功后要做的事情
        console.log(res)
        console.log(res.shareTickets[0])
        wx.showToast({
          title:"分享成功^O^",
          icon:"success",
          duration:2500
        });
        wx.getShareInfo({
          shareTicket: res.shareTickets[0],
          success: (res)=> { 
            // that.setData({
            //   isShow:true
            // }) 
            // console.log(that.setData.isShow)
            console.log("2"+res.data)
           },
          fail: function (res) { console.log("失败"+res) },
          complete: function (res) { console.log("成功"+res) }
        })
      },
      fail: function (res) {
        // 分享失败
        console.log(res)
      }
    }
  }

}) 